<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        body {}

        .hk-list-header {
            background-color: #f1f1f1;
            position: relative;
            font-size: 0.6rem;
            padding: 0.3rem 0.75rem;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-pack: justify;
            -webkit-justify-content: space-between;
            justify-content: space-between;
            -webkit-box-align: center;
            -webkit-align-items: center;
            align-items: center;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            个人中心
        </div>
    </header>
    <div class="aui-content" style="margin-top:50px;">
        <ul class="aui-list aui-media-list">
            <li class="aui-list-item aui-list-item-middle">
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-media" style="width: 3rem;">
                        <img src="../image/login_username_icon@2x.png" class="aui-img-round aui-list-img-sm">
                    </div>
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-text">
                            <div class="aui-list-item-title aui-font-size-18" id="username">请登录</div>
                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="aui-content">
        <ul class="aui-list aui-list-in">
            <li class="hk-list-header"></li>
            <!-- <li class="aui-list-item aui-list-item-middle" onclick='setLock();'>
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-scan"></i>
                </div>
                <div class="aui-list-item-inner">手势密码</div>
                <div class="aui-list-item-inner aui-list-item-arrow"></div>
            </li> -->

            <li class="aui-list-item">
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-voice"></i>
                </div>
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-title">语音播报</div>
                    <div class="aui-list-item-right">
                        <input type="checkbox" class="aui-switch" id="voiceId">
                    </div>
                </div>
            </li>

            <li class="aui-list-item">
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-voice"></i>
                </div>
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-title">声音提示</div>
                    <div class="aui-list-item-right">
                        <input type="checkbox" class="aui-switch" id="speechId">
                    </div>
                </div>
            </li>

            <li class="aui-list-item aui-list-item-middle" onclick='openTelnetApp();'>
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-service"></i>
                </div>
                <div class="aui-list-item-inner">远程协助</div>
                <div class="aui-list-item-inner aui-list-item-arrow"></div>
            </li>
        </ul>
    </div>
    <div class="aui-content">
        <ul class="aui-list aui-list-in">
            <li class="hk-list-header"></li>
            <li class="aui-list-item aui-list-item-middle" onclick='getAppVer();'>
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-upload"></i>
                </div>
                <div class="aui-list-item-inner">检查更新</div>
                <div class="aui-list-item-inner aui-list-item-arrow"></div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-voice"></i>
                </div>
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-title">自动登陆</div>
                    <div class="aui-list-item-right">
                        <input type="checkbox" class="aui-switch" id="autoLoginId">
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="aui-content">
        <ul class="aui-list aui-list-in">
            <li class="hk-list-header"></li>
            <li class="aui-list-item aui-list-item-middle" onclick='openAbout();'>
                <div class="aui-list-item-label-icon">
                    <i class="aui-iconfont aui-icon-info"></i>
                </div>
                <div class="aui-list-item-inner">关于</div>
                <div class="aui-list-item-inner aui-list-item-arrow"></div>
            </li>
        </ul>
    </div>
    <div class="aui-content aui-padded-t-10">
        <div class="aui-card-list" onclick='logout();'>
            <div class="aui-card-list-footer aui-text-center aui-font-size-18">
                退出登录
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //初始化
    apiready = function() {

        api.addEventListener({
            name: 'loginSuccess'
        }, function(ret, err) {

            if (ret) {

                window.location.reload();
            }
        });

        //获取登录者
        var usrname = localStorage.getItem('un');
        // alert("个人中心登录账号：" + usrname);
        $("#username").html(usrname);

    };

    //手势密码
    function setLock() {
        var un = localStorage.getItem('un');
        var screanlockflag = localStorage.getItem(un + 'screanlockflag');

        //存在手势密码
        if (screanlockflag == '1') {

            api.openWin({
                name: "screenpersonchecklock",
                url: "screenpersonchecklock.html"
            });

            //新建手势密码
        } else {

            api.openWin({
                name: "screenpersonsetlockNew_win",
                url: "screenpersonsetlockNew_win.html"
            });
        }
    }

    //远程协助
    function openTelnetApp() {
        api.openApp({
            //androidPkg: 'com.teamviewer.teamviewer.market.mobile',
            androidPkg: 'com.realvnc.viewer.android',
            mimeType: 'text/html'
        }, function(ret, err) {
            if (ret) {
                alert(JSON.stringify(ret));
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    //检查更新
    function getAppVer() {
      console.log("netChoice:"+localStorage.getItem('netChoice'));
      var serverIp = "";
      var serverPort = "";
      var serverProject = "";
  		//判断是内网还是外网配置
  		var netChoice=localStorage.getItem('netChoice');
  		if(netChoice=="out"){
  			//外网访问
  			serverIp = localStorage.getItem('serverIpW');
  			serverPort = localStorage.getItem('serverPortW');;
  			serverProject = localStorage.getItem('serverProjectW');
  		}else{
  			//内网访问
  			serverIp = localStorage.getItem('serverIpN');
  			serverPort = localStorage.getItem('serverPortN');;
  			serverProject = localStorage.getItem('serverProjectN');
  		}
        var appname="HKAPP_";//apk名称
        var url = "http://" + serverIp + ":" + serverPort + "/" + serverProject + "/app/getAppVer";
        var oldVer = api.appVersion; //应用版本号
        // alert("APP版本：" + oldVer);

        var data = {
            values: {
                ver: oldVer,
                appName: appname
            }
        };
      //  alert("44url:"+url);
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
          // alert("44:"+JSON.stringify(ret));
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");

                if (map.result != null && map.result != undefined && map.result != "") {
                    var retData = map.result.split(":");
                    if (retData[0] == "S") {
                        var ver = retData[1]; //版本号
                        alert("APP最新版本：" + ver);
                        checkUpdate(serverIp, serverPort, serverProject, ver);
                    } else {
                        alert(retData[1]);
                    }
                } else {
                    alert(" 当前APP已经是最新版本，版本号" + oldVer);
                }
            } else {
                alert(JSON.stringify(ret))
            }
        });
    }

    //强制更新
    function checkUpdate(serverIp, serverPort, serverProject, ver) {
        var msg = "版本号：" + ver;
        api.confirm({
            title: '强制更新APP',
            msg: msg,
            buttons: ['确定', '取消']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                var downloadUrl = "http://" + serverIp + ":" + serverPort + "/download/" + "HKAPP_" + ver + ".apk";
                // var url = "http://" + serverIp + ":" + serverPort + "/" + serverProject + "/app/download";
                console.log(downloadUrl);
                api.download({
                    url: downloadUrl,
                    report: true,
                    savePath: 'fs://' + 'HKAPP_' + ver + '.apk',
                }, function(ret, err) {
                    if (ret && 0 == ret.state) { /* 下载进度 */
                        api.toast({
                            msg: "正在下载应用" + ret.percent + "%",
                            duration: 10000
                        });
                    }

                    if (ret && 1 == ret.state) { /* 下载完成 */
                        var savePath = ret.savePath;
                        // alert(ret.savePath);
                        api.installApp({
                            appUri: savePath
                        });
                    }

                    if (ret && 2 == ret.state) {
                        api.toast({
                            msg: "下载失败",
                            duration: 10000
                        });
                    }
                });
            } else {
                api.closeWidget({
                    silent: true
                });
            }
        });
    }

    //关于
    function openAbout() {

    }

    //退出登录
    function logout() {
        // api.closeWidget({
        //     silent: true
        // });
        api.openWin({
            name: "login",
            url: "login.html"
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
